//
//  ZjypMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-3-25.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "ZjypMainViewController.h"
#import "GdMainViewController.h"

#import "ZjypSubView.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) 

#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))


@interface ZjypMainViewController ()

@end

@implementation ZjypMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self AddImageView];
    
    [self addBtns:[self AddScrollView]];
    
    [self AddImageView2];
    
    [self.view addSubview:view];
}



-(void)AddImageView{
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
//    view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)];
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight([self.view bounds]))];
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    
//    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(view.bounds), CGRectGetHeight(view.bounds))]autorelease];
    [imageView setImage:[UIImage imageNamed:@"bgImg_zjyp.png"]];
    //[self.view addSubview:imageView];
    [view addSubview:imageView];

}

-(void)AddImageView2{
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    
//    UIImageView *imageView2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 360+diff, 320, 52)];
    UIImageView *imageView2=[[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(view.bounds) - (52 + 50), 320, 52)];
    imageView2.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [imageView2 setImage:[UIImage imageNamed:@"gd_blueImg.png"]];
    imageView2.userInteractionEnabled = YES;
    //[self.view addSubview:imageView2];
    [view addSubview:imageView2];
    
    CGRect frame1=CGRectMake(7, 6, 40, 40);
    CGRect frame2=CGRectMake(60, 6, 40, 40);
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"gd_zjyp.png"] forState:UIControlStateNormal];
    btn1.frame = frame1;
    [btn1 addTarget:self action:@selector(Button7Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"gd_xgxx.png"] forState:UIControlStateNormal];
    btn2.frame = frame2;
    [btn2 addTarget:self action:@selector(Button8Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[self.view addSubview:btn1];
    //[self.view addSubview:btn2];
    [imageView2 addSubview:btn1];
    [imageView2 addSubview:btn2];
}

-(void)Button7Clicked{
    
}

-(void)Button8Clicked{

    GdMainViewController *gb=[[GdMainViewController alloc]init];
    if(!IOS_VERSION_7_OR_ABOVE) {
        gb.view.frame=CGRectMake(0, -20, 320, 480);
    }
    [self.view addSubview:gb.view];
    
    //UINavigationController *navController =[[UINavigationController alloc] initWithRootViewController:gb];
    //[self.view insertSubview:gb.view aboveSubview:self.view];
    //[self.view.superview addSubview:gb.view];
    //[self.view bringSubviewToFront:gb.view];
    //self.view=gb.view;

}

-(UIScrollView *)AddScrollView{
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 160+diff/1.7, 320, 411)]autorelease];
    //[scrollView setBackgroundColor:[UIColor grayColor]];
    [scrollView setContentSize:CGSizeMake(320, 540-diff)];
    //[self.view addSubview:scrollView];
    [view addSubview:scrollView];
    return scrollView;
}

-(void)addBtns:(UIScrollView *)ScrollView{

    
    CGRect frame1=CGRectMake(20, 20, 124, 82);
    CGRect frame2=CGRectMake(180, 20, 124, 82);
    CGRect frame3=CGRectMake(20, 120, 124, 82);
    CGRect frame4=CGRectMake(180, 120, 124, 82);
    CGRect frame5=CGRectMake(20, 220, 124, 82);
    CGRect frame6=CGRectMake(180, 220, 124, 82);
    
    //UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //btn1.backgroundColor = [UIColor clearColor];
    //[btn1 setTitle:@"返回首页" forState:UIControlStateNormal];
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"btn_dlwz.png"] forState:UIControlStateNormal];
    btn1.frame = frame1;
    [btn1 addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"btn_xzqh.png"] forState:UIControlStateNormal];
    btn2.frame = frame2;
    [btn2 addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setImage:[UIImage imageNamed:@"btn_jjfz.png"] forState:UIControlStateNormal];
    btn3.frame = frame3;
    [btn3 addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn4 setImage:[UIImage imageNamed:@"btn_bnsz.png"] forState:UIControlStateNormal];
    btn4.frame = frame4;
    [btn4 addTarget:self action:@selector(Button4Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn5 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn5 setImage:[UIImage imageNamed:@"btn_bngy.png"] forState:UIControlStateNormal];
    btn5.frame = frame5;
    [btn5 addTarget:self action:@selector(Button5Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn6 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn6 setImage:[UIImage imageNamed:@"btn_bndx.png"] forState:UIControlStateNormal];
    btn6.frame = frame6;
    [btn6 addTarget:self action:@selector(Button6Clicked) forControlEvents:UIControlEventTouchUpInside];
    
    [ScrollView addSubview:btn1];
    [ScrollView addSubview:btn2];
    [ScrollView addSubview:btn3];
    [ScrollView addSubview:btn4];
    [ScrollView addSubview:btn5];
    [ScrollView addSubview:btn6];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(void)Button1Clicked{

    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];

    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    
    [subView showHtml:1];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
}

-(void)Button2Clicked{
    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    [subView showHtml:2];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
 
}

-(void)Button3Clicked{
    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    [subView showHtml:3];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
 
}

-(void)Button4Clicked{
    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    [subView showHtml:4];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
 
}

-(void)Button5Clicked{
    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    [subView showHtml:5];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
    
}

-(void)Button6Clicked{
    ZjypSubView *subView=[[[ZjypSubView alloc]init]autorelease];
    int diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [subView setFrame:CGRectMake(0, 87+diff/1.7, 320, 500)];
    [subView showHtml:6];
    [subView setBackgroundColor:[UIColor colorWithRed:0.937 green:0.918 blue:0.906 alpha:1]];
    [self.view addSubview:subView];
    
}


- (void)viewDidUnload {
    [super viewDidUnload];
}
@end









